package person.bangbang.im.Androidgin.UI;

import java.util.List;

import person.bangbang.im.Androidgin.R;
import person.bangbang.im.Androidgin.Framework.Buddy;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;


public class ContactAdapter extends ArrayAdapter<Buddy> {
	private int mRes;
	@SuppressWarnings("unchecked")
	public ContactAdapter(Context context, int resource,
			List objects) {
		super(context, resource,objects);
		mRes = resource;
	}
	
	public ContactAdapter(Context applicationContext, int resource) {
		super(applicationContext, resource);
		mRes = resource;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LinearLayout l = new LinearLayout(getContext());
		
		if (null != convertView) {
			l = (LinearLayout) convertView;
		} else {
			LayoutInflater inflater = 
				(LayoutInflater) getContext()
			                     .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			l = (LinearLayout) inflater.inflate(mRes, l, true);
		}
		TextView nameV = ((TextView)l.findViewById(R.id.contact_name));
		TextView idV = ((TextView)l.findViewById(R.id.contact_id));
		
		nameV.setText(getItem(position).getUserName());
		idV.setText(getItem(position).getID());
		return l;
	}


}
